package com.cc.service

import com.cc.mapper.ScriptMapper
import com.cc.mapper.ScriptRecordMapper
import com.cc.model.Script
import com.mybatisflex.spring.service.impl.ServiceImpl
import org.springframework.stereotype.Service

/**
 * ScriptService
 * @author aa
 * @since 2024/4/22
 * @version 1.0
 */
@Service
class ScriptService(
    private val scriptMapper: ScriptMapper,
    private val scriptRecordMapper: ScriptRecordMapper,
) : ServiceImpl<ScriptMapper, Script>() {
    fun taskCount(): Map<String, Int> {
        var transTaskNum = 0
        var jobTaskNum = 0
        val scripts = scriptMapper.taskCount()
        for (script in scripts) {
            if (script.scriptType == "1") {
                // 统计运行的转换数量
                transTaskNum = script.num
            } else if (script.scriptType == "0") {
                // 统计运行的作业数量
                jobTaskNum = script.num
            }
        }

        return mapOf(
            "totalTaskNum" to transTaskNum + jobTaskNum,
            "transTaskNum" to transTaskNum,
            "jobTaskNum" to jobTaskNum
        )

    }

    fun runStatus(): Map<String, Any> {
        val get7DayScriptRunstatusForMysql = scriptRecordMapper.get7DayScriptRunstatusForMysql()

        return get7DayScriptRunstatusForMysql;
    }
}